package classes
{
	import flash.events.Event;
	
	import mx.core.UIComponent;
	import mx.effects.Fade;
	import mx.effects.Sequence;
	import mx.effects.easing.Linear;
	import mx.events.EffectEvent;	
	import mx.controls.Alert;
	
	public class effects_class extends UIComponent
	{
		private var sequence_effect:Sequence;
		private var delay_effect:int = 1000;
		
		public function effects_class(arr_obj:Array, type:String, delay:int=400){
			this.delay_effect = delay;
			sequence_effect = new Sequence();
			set_effects(arr_obj, type);
		}
		
		public function set_effects(arr_obj:Array, type:String): void {
			if(arr_obj){
				for(var i:int=0; i<arr_obj.length; i++){
					this.add_effect(arr_obj[i], type);
				}
				sequence_effect.addEventListener(EffectEvent.EFFECT_END, listener_effect_end);
				sequence_effect.play();
				
			}
		}
		
		public function listener_effect_end(event:EffectEvent): void {
			//Alert.show('done');
			//this.dispatchEvent(new Event('effect_end', true));
		}
		
		private function add_effect(obj:Object, type:String): void {
			if(type == 'FADE'){
				obj.alpha = 0;
				sequence_effect.addChild(apply_fadein_animation(obj));
			}else if(type == 'FADEOUT'){
				sequence_effect.addChild(apply_fadeout_animation(obj));
			}
		}
		
		private function apply_fadein_animation(obj_fade:Object):Fade {
			var eff_fade:Fade = new Fade(obj_fade);
			eff_fade.alphaTo = 1;
			eff_fade.easingFunction = mx.effects.easing.Linear.easeIn;
			eff_fade.duration = this.delay_effect;
			return eff_fade;
		}
		
		private function apply_fadeout_animation(obj_fade:Object):Fade {
			var eff_fade:Fade = new Fade(obj_fade);
			eff_fade.alphaTo = 0;
			eff_fade.easingFunction = mx.effects.easing.Linear.easeIn;
			eff_fade.duration = this.delay_effect;
			return eff_fade;
		}

	}
}